package com.chaobl.goods.carousel.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chaobl.goods.carousel.entity.Carousel;
import com.chaobl.goods.carousel.service.ICarouselService;
import com.chaobl.goods.catalog.entity.Catalog;
import com.chaobl.goods.catalog.service.ICatalogService;
import com.chaobl.goods.shop.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 导航图 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-04-19
 */
@RestController
@RequestMapping("/carousel/carousel")
public class CarouselController {
    @Autowired
    RedisService redisService;

    @Autowired
    ICarouselService carouselService;

    @GetMapping("/list")
    public Object list(Integer enterpriseId, Integer shopId) {
        String key = "/carousel/carousel/list" + enterpriseId + "_" + shopId;
        Object obj = redisService.get(key);
        if(obj != null)
            return obj;


        List list = carouselService.list(new QueryWrapper<Carousel>().eq("firmid", enterpriseId)
                .eq("shopId", shopId));

        if(list != null && list.size() > 0)
            redisService.set(key, list);

        return list;

    }
}
